<%-- 
    Document   : startpage
    Created on : Dec 4, 2009, 11:28:50 PM
    Author     : gabriel
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.com.zumbits.avd.web.client.Conn" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

    <head>
        <script src="./lib/jquery.js" type="text/javascript"></script>
        <script src="./lib/jquery.cookie.js" type="text/javascript"></script>
        <script src="./lib/jquerycolorize/jquery.colorize.js" type="text/javascript"></script>
        <script src="./lib/jquerytreeview/jquery.treeview.js" type="text/javascript"></script>
        <script type="text/javascript">
            $('document').ready(function(){

                $('#dir_table').colorize({oneClick:true});
                $('#dir_arvore').treeview();
                $('#browser').treeview();
                showMessage();
            });
            openFolder = function(path){
                window.location = "startpage.jsp?currentPath="+path;
            };
            downloadFile = function(path, file){
                window.location = "downloadaction.jsp?currentPath="+path+"&fileName="+file;
            };
            createFolder = function(path){
                file = $('#novaPasta').val();
                if (file == "") return;
                if(confirm("Criando pasta "+file+" dentro de "+path+"\nContinuar?"))
                    window.location = "createfolderaction.jsp?currentPath="+path+"&name="+file;
            };
            deleteFile = function(path, name){
                if(confirm("Tem certeza de que deseja excluir "+name+"?"))
                    window.location = "deleteaction.jsp?currentPath="+path+"&name="+name;
            };
            showMessage = function(){
            <%
            String message = (String) session.getAttribute("message");
            if (message != null) {
                session.removeAttribute("message");
            %>
                    alert("<%out.print(message);%>");
            <%
            }
            %>
                }
        </script>


        <title>Disco Virtual</title>
        <link rel=StyleSheet href="stylesheets/style.css" type="text/css">
        <link rel=StyleSheet href="lib/jquerytreeview/jquery.treeview.css" type="text/css">

        <%
            Conn c = (Conn) session.getAttribute("conn");
            String session_id = (String) session.getAttribute("session_id");
            String currentPath = request.getParameter("currentPath");
            //String message = (String) session.getAttribute("message");
%>
    </head>

    <body>
        <div id="pag">  <!--div da pagina toda, contem as formatacoes gerais da pagina -->
            <div id="header">  <!-- div de cabecalho -->
                <h1>Disco Virtual</h1>
                <div class="description">Universidade Federal do Cear&aacute;</div>
            </div>

            <div id="corpo">  <!-- corpo do template-->
                <div id="lado_esq">  <!-- menu esquerdo, onde vai ficar o login, o upload e a arvore-->
                    <div id="arvore"> <!-- div da arvore de diretorios-->
                        <h2>Diret&oacute;rio</h2>
                        <ul id="dir_arvore" class="filetree">
                            <ul>
                                <li class="closed"><span class="folder" onclick="openFolder('/')">/</span>
                                    <%out.println(c.listUl(session_id, "/"));%>
                                </li>
                            </ul>
                        </ul>
                        <!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>

                        <!------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------>
                    </div>                    
                </div>

                <div id="lado_dir">
                    <table width="100%">
                        <tr><td><h3><i>Bem-vindo: <b>${username}</b></i></h3></td> <td align="right"><a href="logoutaction.jsp">logout</a></td></tr>
                    </table>
                    <%
            if (currentPath != null) {
                    %>
                    <h4>Exibindo conte&uacute;do de:
                        <%
                currentPath = currentPath.replace("//", "/");
                out.print(currentPath);
                        %></h4>
                    <p>
                        <i>

                            <span><input type="text" id ="novaPasta" size="65" name="novaPasta"/></span><span onclick="createFolder('<%out.print(currentPath);%>')"><img alt="create folder" src="icons/criar_pasta.gif" style="cursor:pointer;" title="Criar nova pasta" /></span>
                            <br><br><br>
                            <table id="dir_table" width="100%"><th colspan="2">Arquivo</th><th width="5">A&ccedil;&otilde;es</th>
                                <%
                out.println(c.listTable(session_id, currentPath));
                                %>
                            </table>
                        </i>
                    </p>
                    <div id="upload">
                        <h4>Upload...</h4>
                        <%
                            session.setAttribute("buttonSend", "Send");
                        %>
                        <form action="uploadaction.jsp?currentPath=<%out.println(currentPath);%>" method="post" ENCTYPE="multipart/form-data">
                            <input type="file" name="arquivo" id="arquivo" size="40" />
                            <input type="submit" name="buttonSend" value="Send" />
                        </form>

                    </div>
                    <% } else {%>
                    <h2>Parametro incorreto</h2>
                    <% }%>
                </div>

            </div>

            <div id="creditos">
                Desenvolvido por <b>Zumbits</b>
            </div>
        </div>
    </body>
</html>